package com.menhai.personmanagement.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.menhai.personmanagement.entity.HealthEncyclopediaDirectory;
import com.menhai.personmanagement.mapper.HealthEncyclopediaDirectoryMapper;
import com.menhai.personmanagement.utils.UuidUtil;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/HealthEncyclopediaDirectory")
public class HealthEncyclopediaDirectoryController {
	@Autowired
	private HealthEncyclopediaDirectoryMapper HealthEncyclopediaDirectoryMapper;

	//初始化目录
	@RequestMapping("/directory")
	public List<HealthEncyclopediaDirectory> directory (HealthEncyclopediaDirectory HealthEncyclopediaDirectory){
		List<HealthEncyclopediaDirectory> HealthEncyclopediaDirectoryList = new ArrayList<HealthEncyclopediaDirectory>();
		HealthEncyclopediaDirectoryList = directoryMapper(HealthEncyclopediaDirectory);
        return HealthEncyclopediaDirectoryList;
   }
	//新建保存
	@RequestMapping("/del")
	public Object del(HealthEncyclopediaDirectory HealthEncyclopediaDirectory) throws Exception{
   	 	HealthEncyclopediaDirectory.setList_id(UuidUtil.uuid());
		return delMapper(HealthEncyclopediaDirectory);
	   }
	//删除
	@RequestMapping("/delete")
	public Object delete(HealthEncyclopediaDirectory HealthEncyclopediaDirectory) throws Exception{
		return deleteMapper(HealthEncyclopediaDirectory); 
	   }
	//编辑
	@RequestMapping("/dels")
	public Object dels(HealthEncyclopediaDirectory HealthEncyclopediaDirectory) throws Exception{
		return delsMapper(HealthEncyclopediaDirectory); 
	   }
	public List<HealthEncyclopediaDirectory> directoryMapper(HealthEncyclopediaDirectory HealthEncyclopediaDirectory) {
		return HealthEncyclopediaDirectoryMapper.directory(
				HealthEncyclopediaDirectory.getSelect_identity(),
				HealthEncyclopediaDirectory.getParent_list_id()
			);
	}
	public Map<String, Object> delMapper(HealthEncyclopediaDirectory HealthEncyclopediaDirectory) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
  		int iRet = HealthEncyclopediaDirectoryMapper.del(HealthEncyclopediaDirectory);
  		if(iRet == 0){  //没有插入成功的数据
				resultMap.put("success", "0");
				resultMap.put("message", "插入成功的条数为0，新建健康百科目录失败！");
				return resultMap;
			}else{
				resultMap.put("success", "1");
				resultMap.put("message", "新建健康百科目录成功！");
				return resultMap;
			}
	}
	public Map<String, Object> deleteMapper(HealthEncyclopediaDirectory HealthEncyclopediaDirectory) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
  		int iRet = HealthEncyclopediaDirectoryMapper.delete(HealthEncyclopediaDirectory);
  		if(iRet == 0){  //没有插入成功的数据
				resultMap.put("success", "0");
				resultMap.put("message", "插入成功的条数为0，删除健康百科目录失败！");
				return resultMap;
			}else{
				resultMap.put("success", "1");
				resultMap.put("message", "删除健康百科目录成功！");
				return resultMap;
			}
	}
	public Map<String, Object> delsMapper(HealthEncyclopediaDirectory HealthEncyclopediaDirectory) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
  		int iRet = HealthEncyclopediaDirectoryMapper.dels(HealthEncyclopediaDirectory);
  		if(iRet == 0){  //没有插入成功的数据
				resultMap.put("success", "0");
				resultMap.put("message", "插入成功的条数为0，编辑健康百科目录失败！");
				return resultMap;
			}else{
				resultMap.put("success", "1");
				resultMap.put("message", "编辑健康百科目录成功！");
				return resultMap;
			}
	}
}
